#!/usr/bin/env python
import sqlite3, argparse

from time import strftime, localtime, gmtime
#This opens a connection to the AddressBook db and runs a query to get the appropriate info to return it to the standard output.

def run(s):
	#check if the file AddressBook.sqlitedb is there
	# try:
		print('Found "{}"'.format(s))
		#connect to the db

		conn = sqlite3.connect(s)
		c = conn.cursor()
		#print the column headers
		print()
		#get the table to print

		for rowid, first, last, value, creationdate , ModificationDate in c.execute('SELECT rowid, first, last, value, creationdate , ModificationDate   FROM ABPerson, ABMultivalue WHERE rowid = record_id'):
			# #convert the time to the usual format
			creationTime = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(creationdate+978307200))
			modificationTime = strftime('%Y-%m-%d %H:%M:%S (%Z)', localtime(ModificationDate+978307200))
			# #convert the row id into string

			row = str(rowid)

			# #prints the values
			# print('{0:10}{1:15}{2:30}{3:20}{4:20}{5:10}'.format(row, address, time, text, flagVal, readVal))
			#print('{} {} {} {}'.format(rowid, first, last, value))
			print('{0:5} {1:10} {2:20} {3:30} {4:30} {5:20}'.format(row, first, last , value, creationTime , modificationTime ))

		#endofloop
			
	# except sqlite3.Error:
	# 	print('The AddressBook.db is not placed in the current working directory')    




def main():
	#run the run() function
	databaseName = 'AddressBook.sqlitedb'
	run(databaseName)


if __name__ == '__main__':
	main()